<?php

/**
 * @author aisyah
 * @copyright 2012
 */

//session_start();
require_once("../dao/database.php");
require_once("../dao/order_dao.php");

include("header.php");
echo "<div class='container'>
		<div class='row'>";

$order = new Order_Dao($class_db);
        
function sesi_alamat(Order_Dao $order, Database $class_db){
    
    $name = $_SESSION['alamat']['name'];
                $street = $_SESSION['alamat']['street'];
                $kecamatan = $_SESSION['alamat']['kecamatan'];
                $city = $order->cek_city_prov_id($_SESSION['alamat']['city'],2);
                $province = $order->cek_city_prov_id($_SESSION['alamat']['province'],1);
                $zip_code = $_SESSION['alamat']['zip_code'];
                                             
                
                echo "                
                <div><h2>Alamat Pengiriman</h2></br>
                <form name=fr_alamat class=form method=POST action='product_aksi.php?modul=calamat' onSubmit='return cekAlamat()' enctype=multipart/form-data>
                <table class=table>
                <tr><td>Nama(*) </td><td><input type=text name=name value=$name></td></tr>
                <tr><td>Jalan(*) </td><td><textarea name=street>$street</textarea></td></tr>
                <tr><td>Kecamatan(*) </td><td><input type=text name=kecamatan value=$kecamatan></td></tr>
                
                <tr><td>Provinsi(*) </td><td><select name=province id=province >";
                
                //<input type=text name=city value=$city>
                $class_db->hasil="";
                $class_db->show_Data('t_province');
                $province2 = $class_db->get_hasil();
                //print_r($prov);
                foreach($province2 as $hasil){
                    if($hasil['province_id']==$province){
                        echo "<option value=$hasil[province_id] selected>$hasil[name]</option>";
                        //$id_prov = $hasil['province_id'];
                    }else{
                        echo "<option value=$hasil[province_id]>$hasil[name]</option>";
                    }
                }
                
                echo "</select></td></tr>
                <tr><td>Kota(*) </td><td><select name=city id=city>";
                /*echo "<option>--pilih kota--</option>";
                
                //<input type=text name=city value=$city>
                $class_db->hasil="";
                //$class_db->show_Data('t_city','*',null,null,'province_id='.$province);
                $class_db->show_Data('t_city');
                //$class_db->show_Data('t_city');
                $city2 = $class_db->get_hasil();
                //print_r($city2);
                foreach($city2 as $hasil2){
                    if($hasil2['city_id']==$city){
                        echo "<option value=$hasil2[city_id] selected>$hasil2[city_name]</option>";
                    }else{
                        echo "<option value=$hasil2[city_id]>$hasil2[city_name]</option>";
                    }
                }*/
                
                echo "</select></td></tr>
                <tr><td>Kode Pos(*) </td><td><input type=text name=zip_code value=$zip_code></td></tr>
                <tr><td colspan=2><input class='btn btn-primary pull-right' type=submit value='Simpan Alamat'></td></tr>
                </form>                
                </table></div>";
}

function no_sesi_alamat(Database $class_db){
    echo "<div class=span7><div><h2>Alamat Pengiriman</h2></br>                  
                <form name= fr_alamat class=form method=POST action='product_aksi.php?modul=calamat' onSubmit='return cekAlamat()' enctype=multipart/form-data>
                <table class=table>
                <tr><td>Nama(*) </td><td><input type=text name=name></td></tr>
                <tr><td>Jalan(*) </td><td><textarea name=street></textarea></td></tr>
                <tr><td>Kecamatan(*) </td><td><input type=text name=kecamatan></td></tr>
                <tr><td>Provinsi(*) </td><td><select name=province>";
                
                //<input type=text name=city value=$city>
                $class_db->hasil="";
                $class_db->show_Data('t_province');
                $province2 = $class_db->get_hasil();
                //print_r($prov);
                foreach($province2 as $hasil){
                    
                        echo "<option value=$hasil[province_id]>$hasil[name]</option>";
                   
                }
                
                echo "</select></td></tr>
                <tr><td>Kota(*) </td><td><select name=city>";
                
                //<input type=text name=city value=$city>
                $class_db->hasil="";
                $class_db->show_Data('t_city');
                //$class_db->show_Data('t_city');
                $city2 = $class_db->get_hasil();
                //print_r($city2);
                foreach($city2 as $hasil2){
                    
                        echo "<option value=$hasil2[city_id]>$hasil2[city_name]</option>";
                    
                }
                
                echo "</select></td></tr>
                <tr><td>Kode Pos(*) </td><td><input type=text name=zip_code></td></tr>
                <tr><td colspan=2><input class='btn btn-primary pull-right' type=submit value='Simpan Alamat'></td></tr>
                </form>                
                </table></div>";    

}

include("sidebar.php");

$modul=$_GET['modul'];



switch($modul){
    
    default :
        echo "<div class=span7>        
        <h2>Keranjang Belanja</h2>
        
            <table class=table>
            <tr><th>No</th><th>Produk</th><th>Nama Produk</th><th>Jumlah</th><th>Harga</th><th>Sub Total</th><th>Hapus</th><tr>";
            
       $max=count(array_keys($_SESSION['cart']));      
       
       $no=1;
       $total = 0;   
       
       foreach(array_keys($_SESSION['cart']) as $key){
        
            $class_db->show_Data('product_detail','*',null,null,'productdet_id='.$_SESSION['cart'][$key]['productid']);
       
            $hasil=$class_db->get_hasil();
            
            foreach($hasil as $data){
        
            $jml=$_SESSION['cart'][$key]['qty'];
            $harga=number_format($data['price'],2,',','.');
            $sub = number_format($jml*$data['price'],2,',','.');
            
            echo "<tr>
                    <td>$no</td>
                    <td><div class=span1><img height=50px src='../../images/produk/$data[image]'></div></td>
                    <td>$data[product_name]</td>
                    <td><input type=text size=4 name=jumlah value=$jml ><br/>
                    <a href='product_aksi.php?modul=tambah&id=$key'><img src='../../images/plus.png'></a>
                    <a href='product_aksi.php?modul=kurang&id=$key'><img src='../../images/minus.png'></a><br/></td>
                    <td>Rp. $harga</td>
                    <td>Rp. $sub</td>
                    <td><a href='product_aksi.php?modul=hapus&id=$key'><img src='../../images/delete_icon.png'></a></td>
                </tr>";            
               
       }
       
       $total += $_SESSION['cart'][$key]['prc'];
       
       $no++;
        
       } 
       $_SESSION['subtotal'] = $total;
        echo "<tr><td colspan=4></td><td><b>Total</b></td><td><b>Rp. ".number_format($total,2,',','.')."</b></td><td></td></tr>
        
        <tr><td><a href='cat_view.php?modul=semua'>Lanjutkan Belanja</a></td><td></td><td></td>
        <td></td><td></td><td></td>
        <td>";
        if(isset($_SESSION['loggedinuser'])){
            if(!is_null($_SESSION['loggedinuser']))
            echo "<a href='cart_view.php?modul=alamat'>Proses</a>
        
            </td></tr>";
        }else{
            echo "<a href='cart_view.php?modul=login_cart'>Proses</a>
        
            </td></tr>";
        }
           


        echo "</table></div></div>";
    break;
    
    //login cart
    
    case "login_cart":
        echo "<div class='span7'>
                            <h1>Login</h1>                        
                    </div>                    

                    <div class='row' id=login>

                        <div class='span4 well'>
                            <h2>Pelanggan Baru</h2>
                            <p>Dengan memiliki akun anda dapat melakukan proses belanja.</p><br />
                            <a href='register.php' class='btn btn-primary pull-right'>Daftar</a>
							
                        </div>	 		

                        <div class='span4 well pull-right'>
                            <h2>Pelanggan</h2>
                            <p>Jika anda sudah terdaftar, silahkan log in.</p>

                            <form name=fr_login class=''  method='post' action='login_aksi.php' onSubmit='return cekLogin()' enctype=multipart/form-data>
								<label>Username</label>
								<input type='text' name='myusername' class='span3' placeholder='Type username here...'/><br/>
								<label>Password</label>
								<input type='text' name='mypassword' class='span3' placeholder='Type password here...'/><br/>
								<button class='btn btn-primary pull right' type='Submit' name='Submit' value='Login'>Submit</button>
		                    </form>

                        </div>

                    </div>
                </div>

            </div>
	
";
    break;
    
    //alamat pengiriman dan penagihan
    case "alamat":
    //echo $_SESSION['alamat']['name']."------------";
        $alamat = array();  
        //alamat pengguna sesuai akun user      
        $query = "SELECT customer_id FROM customer 
                WHERE user_id = (SELECT user_id FROM user WHERE username = '$_SESSION[loggedinuser]')";
        //print_r($query);
        //print_r($_SESSION['loggedinuser']);
        //$class_db->select_table($query);
        //$us = $class_db->hasil;
        $us = $class_db->select_table($query);
        foreach ($us as $user){
            $user = $user['customer_id']; 
        }
        //print_r($user);
        $class_db->hasil ="";
        $class_db->show_Data('customer','*',null,null,'customer_id='.$user);
        $hasil=$class_db->get_hasil();       
        
        if($hasil){
            foreach($hasil as $data){
                $alamat[] = $data['name'];
                $alamat[] = $data['street'];
                $alamat[] = $data['kecamatan'];
                $alamat[] = $data['city'];
                $alamat[] = $data['province'];
                $alamat[] = $data['zip_code'];
            }
        }
        print_r($alamat);
        print_r(count($alamat));
        //nyari city-province
        
        $class_db->hasil="";
        
        $class_db->show_Data('t_city','city_name',null,null,'city_id='.$alamat[3]);
        $city = $class_db->get_hasil();
        //print_r($city);
        foreach($city as $hasil){
            $city = $hasil['city_name'];
        }
        
        $class_db->hasil="";
        $class_db->show_Data('t_province','name',null,null,'province_id='.$alamat[4]);
        $prov = $class_db->get_hasil();
        //print_r($prov);
        foreach($prov as $hasil){
            $province = $hasil['name'];
        }
        
        //if(count($alamat)>0){
        if(count($alamat)>0 and isset($_SESSION['alamat'])){
           echo "<div class=span7><div><h2>Alamat Pelanggan</h2></br>
                <form class=form method=POST action='product_aksi.php?modul=calamat' enctype=multipart/form-data>
                <table class=table>
                <tr><td>Nama </td><td><input type=text name=name readonly=readonly value=$alamat[0]></td></tr>
                <tr><td>Jalan </td><td><input type=text name=street readonly=readonly value=$alamat[1]></td></tr>
                <tr><td>Kecamatan </td><td><input type=text name=kecamatan readonly=readonly value=$alamat[2]></td></tr>
                <tr><td>Kota </td><td><input type=text name=city readonly=readonly value='".$city."'></td></tr>
                <tr><td>Provinsi </td><td><input type=text name=province readonly=readonly value='".$province."'></td></tr>
                <tr><td>Kode Pos </td><td><input type=text name=zip_code readonly=readonly value=$alamat[5]></td></tr>
                <tr><td colspan=2><input class='btn btn-primary pull-right' type=submit value='Samakan Alamat'></td></tr>
                </form></table></div>";
           
           //alamat pengiriman
           
            
                sesi_alamat($order, $class_db);
                
           
           /*else{
                echo "                
                <div><h2>Alamat Pengiriman</h2></br>
                <form class=form method=POST action='product_aksi.php?modul=calamat' enctype=multipart/form-data>
                <table class=table>
                <tr><td>Nama </td><td><input type=text name=name></td></tr>
                <tr><td>Jalan </td><td><textarea name=street></textarea></td></tr>
                <tr><td>Kecamatan </td><td><input type=text name=kecamatan></td></tr>
                <tr><td>Kota </td><td><input type=text name=city></td></tr>
                <tr><td>Provinsi </td><td><input type=text name=province></td></tr>
                <tr><td>Kode Pos </td><td><input type=text name=zip_code></td></tr>
                <tr><td colspan=2><input class='btn btn-primary pull-right' type=submit value='Simpan Alamat'></td></tr>
                </form>                
                </table></div>";
           }*/
           
            
        }else if(count($alamat)>0 and !isset($_SESSION['alamat'])){
            echo "<div class=span7><div><h2>Alamat Pelanggan</h2></br>
                <form class=form method=POST action='product_aksi.php?modul=calamat' enctype=multipart/form-data>
                <table class=table>
                <tr><td>Nama </td><td><input type=text name=name readonly=readonly value=$alamat[0]></td></tr>
                <tr><td>Jalan </td><td><input type=text name=street readonly=readonly value=$alamat[1]></td></tr>
                <tr><td>Kecamatan </td><td><input type=text name=kecamatan readonly=readonly value=$alamat[2]></td></tr>
                <tr><td>Kota </td><td><input type=text name=city readonly=readonly value='".$city."'></td></tr>
                <tr><td>Provinsi </td><td><input type=text name=province readonly=readonly value='".$province."'></td></tr>
                <tr><td>Kode Pos </td><td><input type=text name=zip_code readonly=readonly value=$alamat[5]></td></tr>
                <tr><td colspan=2><input class='btn btn-primary pull-right' type=submit value='Samakan Alamat'></td></tr>
                </form></table></div>";
           
           //alamat pengiriman
           
                echo "<div>";
                no_sesi_alamat($class_db);
                echo "</div></div></div></div><div></div>";
            
        }else if(count($alamat)==0 and !isset($_SESSION['alamat'])){
           /*echo "<div class=span7><div><h2>Alamat Pengiriman</h2></br>                  
                <form name= fr_alamat class=form method=POST action='product_aksi.php?modul=calamat' enctype=multipart/form-data>
                <table class=table>
                <tr><td>Nama(*) </td><td><input type=text name=name></td></tr>
                <tr><td>Jalan(*) </td><td><textarea name=street></textarea></td></tr>
                <tr><td>Kecamatan(*) </td><td><input type=text name=kecamatan></td></tr>
                <tr><td>Provinsi(*) </td><td><select name=province>";
                
                //<input type=text name=city value=$city>
                $class_db->hasil="";
                $class_db->show_Data('t_province');
                $province2 = $class_db->get_hasil();
                //print_r($prov);
                foreach($province2 as $hasil){
                    
                        echo "<option value=$hasil[province_id]>$hasil[name]</option>";
                   
                }
                
                echo "</select></td></tr>
                <tr><td>Kota(*) </td><td><select name=city>";
                
                //<input type=text name=city value=$city>
                $class_db->hasil="";
                $class_db->show_Data('t_city');
                //$class_db->show_Data('t_city');
                $city2 = $class_db->get_hasil();
                //print_r($city2);
                foreach($city2 as $hasil2){
                    
                        echo "<option value=$hasil2[city_id]>$hasil2[city_name]</option>";
                    
                }
                
                echo "</select></td></tr>
                <tr><td>Kode Pos(*) </td><td><input type=text name=zip_code></td></tr>
                <tr><td colspan=2><input class='btn btn-primary pull-right' type=submit value='Simpan Alamat'></td></tr>
                </form>                
                </table></div>";*/
                no_sesi_alamat($class_db); 
        }else if(isset($_SESSION['alamat'])){
            echo "<div class=span7>";
                sesi_alamat($order, $class_db);
                //echo "";   

        }else if(!isset($_SESSION['alamat'])){
             no_sesi_alamat($class_db); 
        }
        
         echo "<div><table class=table>
                <tr><td><a href='cart_view.php'>Kembali</a></td><td></td><td></td><td></td><td></td><td></td>
                <td align=left valign=top><a href='cart_view.php?modul=kirim' onClick='return cekAlamat()'>Lanjut</a></td></tr>
                </table></div></div></div>"; 
        
        //print_r($city2);
    
    break;
    
    //cara pengiriman
    case "kirim":
        echo "<div class=span7>
            <div><h2>Cara Pengiriman</h2></br>
            <form name= fr_kirim class=form-horizontal method=POST action='product_aksi.php?modul=kirim' onSubmit='return cekKirim()' enctype=multipart/form-data>
            <div class=control-group><label class=control-label>Pilih Cara Pengiriman : </br></label>
            <div class=controls><select name=kirim>
            <option value=0 selected>--Pilih Cara Kirim--</option>";
            $class_db->hasil = "";            
            $class_db->show_Data('kirim','*');
            $hasil=$class_db->get_hasil();
            foreach($hasil as $data){
                if($data['id_kirim']==$_SESSION['kirim']){
                    echo "<option value=$data[id_kirim] selected>$data[kirim]</option>";
                }else{
                    echo "<option value=$data[id_kirim]>$data[kirim]</option>";
                }
                              
            }
            
        echo "</select>  &nbsp;&nbsp;&nbsp;&nbsp;<input class='btn btn-primary' type=submit value='Simpan'></div></div>
            
            </form>";
        if(isset($_SESSION['kirim'])){
            $class_db->hasil = "";
            $ses_kirim=$_SESSION['kirim'];
            $class_db->show_Data('kirim','*',null,null,'id_kirim='.$ses_kirim);
            $hasil=$class_db->get_hasil();
            foreach($hasil as $data){
                $cara_kirim = $data['kirim'];                
            }
            echo "<div><div><p>Cara Pengiriman yang anda pilih adalah :".$cara_kirim."</br>
                periksa kembali pilihan anda sebelum melanjutkan!</p></div></div>";
        }
            
        echo "<div><table class=table>
                <tr><td><a href='cart_view.php?modul=alamat'>Kembali</a></td><td></td><td></td><td></td><td></td><td></td>
                <td align=left valign=top ><a href='cart_view.php?modul=bayar' onClick='return sesiKirim()'>Lanjut</a></td></tr>
                </table></div></div></div></div>";
    break;
    
    //cara pembayaran
    case "bayar":
    //echo $_SESSION['bayar'];
        echo "<div class=span7>
            <div><h2>Cara Bayar</h2></br>
            <form name =fr_bayar class=form-horizontal method=POST action='product_aksi.php?modul=bayar' onSubmit='return cekBayar()' enctype=multipart/form-data>
            <div class=control-group><label class=control-label>Pilih Cara Pembayaran : </br></label>
            <div class=controls><select name=bayar>
            <option value=0 selected>--pilih cara pembayaran--</option>";
            $class_db->hasil = "";            
            $class_db->show_Data('bayar','*');
            $hasil=$class_db->get_hasil();
            foreach($hasil as $data){
                if($data['id_bayar']==$_SESSION['bayar']){
                    echo "<option value=$data[id_bayar] selected>$data[bayar]</option>";
                }else{
                    echo "<option value=$data[id_bayar]>$data[bayar]</option>";
                }
                              
            }
            
        echo "</select>  &nbsp;&nbsp;&nbsp;&nbsp;<input class='btn btn-primary' type=submit value='Simpan'></div></div>
            
            </form>";
        if(isset($_SESSION['bayar'])){
            $class_db->hasil = "";
            $ses_bayar=$_SESSION['bayar'];
            $class_db->show_Data('bayar','*',null,null,'id_bayar='.$ses_bayar);
            $hasil=$class_db->get_hasil();
            foreach($hasil as $data){                
                $cara_bayar = $data['bayar'];                
            }
            echo "<div><div>Cara Pengiriman yang anda pilih adalah :".$cara_bayar."</br>
                periksa kembali pilihan anda sebelum melanjutkan!</div></div>";
        }
        
        echo "<div><table class=table>
                <tr><td><a href='cart_view.php?modul=kirim'>Kembali</a></td><td></td><td></td><td></td><td></td><td></td>
                <td align=left valign=top><a href='cart_view.php?modul=summary' onClick='return sesiBayar()'>Lanjut</a></td></tr>
                </table></div></div></div></div>";
    
    break;
    
    //summary order
    case "summary":
        
        $order = new Order_Dao($class_db);
        $no_po = $order->po_number();
        echo "<div class=span7>
        <div class=span6 halign=center><h3>Ringkasan Belanja</h3></br>nomor PO anda : $no_po</div>
        <div class=span6><h3>Produk</h3></br>
        <table class=table>
        <th>No</th><th>Nama Produk</th><th>Jumlah</th><th>Harga Satuan</th><th>Sub Total</th>
        ";
        $max=count(array_keys($_SESSION['cart']));      
       
       $no=1;
       $total = 0;   
       
       foreach(array_keys($_SESSION['cart']) as $key){
        
            $class_db->show_Data('product_detail','*',null,null,'productdet_id='.$_SESSION['cart'][$key]['productid']);
       
            $hasil=$class_db->get_hasil();
            
            foreach($hasil as $data){
        
            $jml=$_SESSION['cart'][$key]['qty'];
            $harga=number_format($data['price'],2,',','.');
            $sub = number_format($jml*$data['price'],2,',','.');
            
            echo "<tr>
                    <td>$no</td>                    
                    <td>$data[product_name]</td>
                    <td>$jml</td>
                    <td>Rp. $harga</td>
                    <td>Rp. $sub</td>                    
                </tr>";            
               
       }
       
       $total += $_SESSION['cart'][$key]['prc'];
       
       $no++;
        
       } 
       
        echo "<tr align=left><td colspan=3></td><td><b>Total</b></td><td><b>Rp. ".number_format($total,2,',','.')."</b></td></tr>
        <tr><td></td><td></td><td></td><td></td><td></td></tr>
        </table>
        </div>
        <div>
        <div class=span3><h3>Alamat Pengiriman</h3></br>
        <table class=table>
        <tr><td>";
        
        echo $order->get_ship_addr();
        
        echo "</td></tr>
        <tr><td></td></tr>
        </table>        
        </div>
        <div class=span3><h3>Cara Pengiriman</h3></br>
        <table class=table>
        <tr><td>";
        //belum selesai--perlu menghitung berat barang & berapa toko. satu barang 0.5 kg misalnya. beda toko 
        //dihitung beda biaya. misal 2 barang dari 2 toko = 2 kg.
        $class_db->hasil = "";
        $ses_kirim=$_SESSION['kirim'];
        $class_db->show_Data('kirim','*',null,null,'id_kirim='.$ses_kirim);
        $hasil=$class_db->get_hasil();
        foreach($hasil as $data){
            $cara_kirim = $data['kirim'];
            $biaya_kg = $data['harga_kg'];
            $_SESSION['biaya_kirim'] = $biaya_kg; 
        }
        $kirim = "Anda memilih media pengiriman ".$cara_kirim.
            " dengan biaya kirim Rp. ".number_format($biaya_kg,2,',','.');
        echo $kirim;
        echo "</td></tr>
        <tr><td></td></tr>
        </table>
        <h3>Cara Pembayaran</h3></br>
        <table class=table>
        <tr><td>";
        //belum selesai--masih dipikirkan apakah per toko rekeningnya ato rekening bersama.
        //$class_db->show_Data('product_detail','*',null,null,'productde_id=');
        $class_db->hasil = "";
        $ses_bayar=$_SESSION['bayar'];
        $class_db->show_Data('bayar','*',null,null,'id_bayar='.$ses_bayar);
        $hasil=$class_db->get_hasil();
        foreach($hasil as $data){
            $id_bayar = $data['id_bayar'];
            $cara_bayar = $data['bayar'];
            $hasil = $data['nomor_rek']." atas nama ".$data['nama_rek'];
        }
        
        if($id_bayar!=1){
            $bayar = "Anda memilih media pengiriman ".$cara_bayar."</br>
            silahkan transfer pembayaran sejumlah Rp. ".number_format($total+$biaya_kg,2,',','.').
            " ke rekening ".$hasil;
        }else{
            $bayar = "Anda memilih media pengiriman ".$cara_bayar."</br>
            silahkan lakukan pembayaran sejumlah Rp. ".number_format($total+$biaya_kg,2,',','.').
            " pada saat barang diterima ke kurir kami.";
        }
        
        echo $bayar;
        echo "</td></tr>
        <tr><td></td></tr>
        </table>
        </div>
        </div>
        
        <div class=span7>
        <table class=table>
        <tr><td><a href='cart_view.php?modul=bayar'>Kembali</a>
        <a href='product_aksi.php?modul=selesai' onClick='return selesai()'><label class='btn btn-primary pull-right'>SELESAI</label></a>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a href='print_order.php'> <label class='btn btn-primary pull-right'>CETAK</label></a>
        </td></tr>
        <tr><td></td></tr>
        </table>
        </div></div></div>";
    break;
}	





include("footer.php");



?>
<script language = "javascript">
function cekAlamat()
{
  if (document.fr_alamat.name.value == "" || 
        document.fr_alamat.street.value == "" ||
        document.fr_alamat.kecamatan.value == "" ||
        document.fr_alamat.zip_code.value == "")
  {
    alert ("Kolom bertanda bintang (*) harus diisi!");
    
    if(document.fr_alamat.name.value == "" ){
        document.fr_alamat.name.focus ();
    }else if(document.fr_alamat.street.value == ""){
        document.fr_alamat.street.focus ();
    }else if(document.fr_alamat.kecamatan.value == ""){
        document.fr_alamat.kecamatan.focus ();
    }else if(document.fr_alamat.zip_code.value == ""){
        document.fr_alamat.zip_code.focus ();
    }
    return false;     
  }
  
  return true;
}

function cekKirim()
{
  if (document.fr_kirim.kirim.value==0) 
  {
    alert ("Anda belum memilih cara pengiriman!");    
    
    return false;     
  }
  
  return true;
}

function cekBayar()
{
  if (document.fr_bayar.bayar.value==0) 
  {
    alert ("Anda belum memilih cara pembayaran!");    
    
    return false;     
  }
  
  return true;
}

function cekLogin()
{
  if (document.fr_login.myusername.value==0) 
  {
    alert ("Nama User harus diisi!");    
    document.fr_login.myusername.focus ();
    return false;     
  }else if(document.fr_login.mypassword.value==0) 
  {
    alert ("Password harus diisi!");    
    document.fr_login.mypassword.focus ();
    return false;     
  }
  
  return true;
}

function sesiKirim()
{
    var session_kirim = '<?php echo $_SESSION['kirim']; ?>';
  if (session_kirim == "") 
  {
    alert ("Anda belum memilih cara pengiriman!");    
    
    return false;     
  }
  
  return true;
}

function sesiBayar()
{
    var session_bayar = '<?php echo $_SESSION['bayar']; ?>';
  if (session_bayar == "") 
  {
    alert ("Anda belum memilih cara pembayaran!");    
    
    return false;     
  }
  
  return true;
}

function selesai()
{
    
  var answer = confirm ("Anda yakin membuat order pembelian?")
    if (answer)
        return true;
    else
        window.location='cart_view.php';
        return false;
    }

//select city lom berhasil
function selectCity(){
    $(document).ready(function(){
        $("#province").change(function(){
            var province = $("#province").val();
            $.ajax({
                type: "POST/GET",
                url: "proses_city.php",
                data: "province="+province,
                success: function(data){
                    $("#city").html(data);
                }
            });
        });
    });
}


</script>
